package main

import (
	"fmt"
	"net"
)

func main() {
	//监听
	listen, err := net.Listen("tcp", "127.0.0.1:8080")

	if err != nil {
		fmt.Println("err = ", err)
		return
	}
	defer listen.Close()

	//阻塞等待用户链接
	conn, err := listen.Accept()
	if err != nil {
		fmt.Println("err = ", err)
	}
	//接收用户的请求

	buf := make([]byte, 1024) // 1024大小的缓冲区
	read, err := conn.Read(buf)
	if err != nil {
		fmt.Println("err = ", err)
	}

	fmt.Println("buf = ", string(buf[:read]))

	defer conn.Close()
}
